package workqueue;

import com.rabbitmq.client.*;
import util.RabbitUtil;

import java.io.IOException;

public class Costomer1 {
  public static void main(String[] args) throws IOException {
    Connection connection = RabbitUtil.getConnection();
    final Channel channel = connection.createChannel();

    channel.basicQos(1);//每次消费一个
    channel.queueDeclare( "work" , false, false,  false ,  null);
    channel.basicConsume("work",false,new DefaultConsumer(channel){
      @Override
      public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        try {
          Thread.sleep(2000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        System.out.println("消费者-1:"+ new String(body));
        channel.basicAck (envelope.getDeliveryTag(), false);
      }
    });
  }
}
